package com.howard.test;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;

/**
 * 注意：防止内存泄露，当一个对象存储到HashSet集合里的时，就不能修改这个对象中的那些参与计算
 * Hash值的字段了，否则对象修改后的hash值与当初存储进HashSet集合中的hash值就不同了，从而造成内存泄露
 *
 * @author Administrator
 *
 */
public class ReflectTest2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Collection<Point> collection = new ArrayList<Point>();

		Point p1 = new Point(3, 3);
		Point p2 = new Point(5, 5);
		Point p3 = new Point(3, 3);

		collection.add(p1);
		collection.add(p2);
		collection.add(p3);
		collection.add(p1);
		System.out.println(collection.size());

		Collection<Point> collection1 = new HashSet<Point>();

		collection1.add(p1);
		collection1.add(p2);
		collection1.add(p3);
		collection1.add(p1);

		System.out.println(collection1.size());
		p1.y = 7; // 会造成内存泄露
		collection1.remove(p1);
		System.out.println(collection1.size());

		Collection<Point> collection3 = new ArrayList<Point>();
		for (int j = 0; j < 4; j++) {
			Point point = new Point(j, j);
			collection3.add(point);
		}
		System.out.println(collection3);
	}

}
